package org.facilscrum.controller;

import org.facilscrum.beans.Burndown;
import java.sql.Date; 
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import org.facilscrum.persistencia.BurndownPersistencia;
import org.facilscrum.interfaces.IController;
import org.facilscrum.generales.Mensajeria;


/**
*
*  @author
*/

public class BurndownController implements Serializable ,IController{
private static final long serialVersionUID = 1L;
private boolean withRelation= true;
public static Exception excepcion;


private Burndown selectedburndown;
private List<Burndown> burndownlist;


@Override
public boolean isWithRelation() {
    return withRelation;
}
@Override
public  void setWithRelation(boolean withRelation) {
    this.withRelation = withRelation;
}
public BurndownController(){
}

public Burndown getSelectedBurndown() {
 return selectedburndown;
}

 public void setSelectedBurndown(Burndown selectedburndown) {
 this.selectedburndown = selectedburndown;
}


public List<Burndown> getBurndownlist() {
  return burndownlist;
}

 public void setBurndownlist(List<Burndown> burndownlist) {
  this.burndownlist = burndownlist;
}
/*
*  getMensaje()
*   devuelve el mensaje encontrado...
*/
public String getMensaje() {
   String lexcepcion = excepcion.toString();
   if (lexcepcion.indexOf(":") != -1) {
       lexcepcion = lexcepcion.substring(lexcepcion.indexOf(":") + 1);
   }
  return lexcepcion;
}


/**
*
* insert()
*/

public boolean insert (Burndown burndown) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(burndown)) {
     if (findByPrimaryKey(burndown)==null) {
         if (!BurndownPersistencia.insert(burndown)) {
                 excepcion = BurndownPersistencia.excepcion;
          }
          else{
             return true;
           }
       }else{
               excepcion=new Exception(bundle.getString("msg.recordexists"));
            return false;
       }
    }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"insert()");
  }
  return false;
}


/**
*
* update()
*/

public boolean update (Burndown burndown) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(burndown)) {
 if (BurndownPersistencia.exists(burndown)) {
     if (!BurndownPersistencia.update(burndown)) {
                excepcion = BurndownPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* update(String sqlupdate)
*/

@Override
public boolean update(String sqlupdate) {
try{
     if (!BurndownPersistencia.update(sqlupdate)) {
                excepcion = BurndownPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public boolean updatePrimaryKey (Burndown burndown_old , Burndown burndown) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
   if (validate(burndown_old)) {
 if (BurndownPersistencia.exists(burndown_old)) {
     if (!BurndownPersistencia.updatePrimaryKey(burndown_old,burndown)) {
                excepcion = BurndownPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"updatePrimaryKey()");
  }
  return false;
}


/**
*
* delete()
*/

public boolean delete (Burndown burndown) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
 if (findByPrimaryKey(burndown)!=null) {
     if (!BurndownPersistencia.delete(burndown)) {
                excepcion = BurndownPersistencia.excepcion;
     }else{
            return true;
           }
   }else{
            excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* delete(String sqldelete)
*/

@Override
public boolean delete(String sqldelete) {
try{
     if (!BurndownPersistencia.delete(sqldelete)) {
                excepcion = BurndownPersistencia.excepcion;
     }else{
            return true;
           }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* deleteAll()
*/

@Override
public boolean deleteAll() {
try{
     if (!BurndownPersistencia.deleteAll()) {
                excepcion = BurndownPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"deleteAll()");
  }
  return false;
}


/**
*
* exists()
*/



public boolean exists(Burndown burndown) {
try{
   return BurndownPersistencia.exists(burndown);
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Exists()");
  }
 return false;
}


/**
*
* findPrimaryKey()
*/



public Burndown findByPrimaryKey(Burndown burndown) {
try{
    this.selectedburndown = BurndownPersistencia.findByPrimaryKey(burndown);
    return selectedburndown;
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByPrimaryKey()");
  }
 return null;
}


/**
*
* findByIdburndown()
*/

public boolean findByIdburndown(Burndown burndown) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.findByIdburndown(burndown,withRelation) ;
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdburndown()");
    }
  return false;
  }


/**
*
* findByIdsprint()
*/

public boolean findByIdsprint(Burndown burndown) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.findByIdsprint(burndown,withRelation) ;
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIdsprint()");
    }
  return false;
  }


/**
*
* findByFecha()
*/

public boolean findByFecha(Burndown burndown) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.findByFecha(burndown,withRelation) ;
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByFecha()");
    }
  return false;
  }


/**
*
* findByPuntos()
*/

public boolean findByPuntos(Burndown burndown) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.findByPuntos(burndown,withRelation) ;
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByPuntos()");
    }
  return false;
  }


/**
*
* findByDiasprint()
*/

public boolean findByDiasprint(Burndown burndown) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.findByDiasprint(burndown,withRelation) ;
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByDiasprint()");
    }
  return false;
  }


/**
*
* locateByParameters()
*/

public boolean locateByParameters(Map parametros) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.locateByParameters(parametros,withRelation);
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
       Mensajeria.MensajeError( ex ,"locateByParameters()");
  }
  return false;
}


/**
*
* Func(String funcion, String campo)
*/

@Override
public Double func(String funcion, String campo) {
  try{
     return BurndownPersistencia.func(funcion,campo);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"func()");
  }
  return 0.0;
}


/**
*
* Double func(String funcion, String campo, String where)
*/

@Override
public Double func(String funcion, String campo,String where) {
  try{
     return BurndownPersistencia.func(funcion,campo,where);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Func()");
  }
  return 0.0;
}


/**
*
* count()
*/

@Override
public Integer count() {
  try{
     int x =BurndownPersistencia.count();
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* count(String sql)
*/

@Override
public Integer count(String sqlquery) {
  try{
     int x =BurndownPersistencia.count(sqlquery);
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* query()
*/

@Override
public boolean query(String query) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.query(query,withRelation);
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"query()");
  }
  return false;
}


/**
*
* orderby()
*/

@Override
public boolean orderby(String query) {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     burndownlist = BurndownPersistencia.orderby(query,withRelation);
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"orderby()");
  }
  return false;
}


/**
*
* selectAll()
*/

@Override


public boolean selectAll() {
  try{
     if(burndownlist != null){
        burndownlist.removeAll(burndownlist);
     }
     Map<String, String> parametros = new HashMap<>();
     burndownlist = BurndownPersistencia.getListRecords(parametros,withRelation);
     if (burndownlist== null) {
                excepcion = BurndownPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
       Mensajeria.MensajeError( ex ,"SelectAll()");
  }
            return false;
}


public boolean validate(Burndown burndown) {
 try{
   java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");

   return true;
 }catch(Exception ex){
   Mensajeria.MensajeError(ex, "validate()");
  return false;

  }
}


}
